import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';

class NavToolsComponent extends StatelessWidget {
  final logic = Get.put(NavToolsLogic());

  @override
  Widget build(BuildContext context) {
    List<String> datas = getDataList();
    return GridView.custom(
        // Container跟随GridView内容变化高度
        shrinkWrap: true,
        // 取消滚动效果
        physics: NeverScrollableScrollPhysics(),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 4,
          mainAxisSpacing: 10.0,
          crossAxisSpacing: 20.0,
        ),
        childrenDelegate: SliverChildBuilderDelegate((context, position) {
          return getItemContainer(datas[position]);
        }, childCount: datas.length));
  }

  List<String> getDataList() {
    List<String> list = [];
    for (int i = 0; i < 7; i++) {
      list.add(i.toString());
    }
    return list;
  }

  List<Widget> getWidgetList() {
    return getDataList().map((item) => getItemContainer(item)).toList();
  }

  Widget getItemContainer(String item) {
    return Container(
      alignment: Alignment.center,
      child: Text(
        item,
        style: TextStyle(color: Colors.white, fontSize: 20),
      ),
      color: Colors.blue,
    );
  }
}
